<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>修改企业</title>
    <link rel="stylesheet" href="layui/css/layui.css">
</head>
<body>
<form class="layui-form layui-container" action="" lay-filter="example">
    <div class="layui-row layui-col-xs6">
        <div class="layui-hide">
            <label class="layui-form-label">企业名字</label>
            <div class="layui-input-block">
                <input type="text" name="enter_id" lay-verify="enter_id" th:attr="value=${enterId}"
                       autocomplete="off" placeholder=""
                       class="layui-input">
            </div>
        </div>
        <div>
            <label class="layui-form-label">企业名字</label>
            <div class="layui-input-block">
                <input type="text" name="enter_name" lay-verify="enter_name" th:attr="value=${enterName}"
                       autocomplete="off" placeholder="输入企业名字"
                       class="layui-input">
            </div>
        </div>
        <hr class="layui-col-lg-offset1">
        <div>
            <label class="layui-form-label">企业地址</label>
            <div class="layui-input-block">
                <input type="text" name="enter_address" lay-verify="enter_address" th:attr="value=${enterAddress}"
                       autocomplete="off"
                       placeholder="输入企业地址"
                       class="layui-input">
            </div>
        </div>
        <hr class="layui-col-lg-offset1">
        <div>
            <label class="layui-form-label">企业法人</label>
            <div class="layui-input-block">
                <input type="text" name="enter_legal" lay-verify="enter_legal" th:attr="value=${enterLegal}"
                       autocomplete="off"
                       placeholder="输入企业法人"
                       class="layui-input">
            </div>
        </div>
        <hr class="layui-col-lg-offset1">
        <div>
            <label class="layui-form-label">企业联系方式</label>
            <div class="layui-input-block">
                <input type="text" name="enter_telphone" lay-verify="enter_telphone" th:attr="value=${enterTelphone}"
                       autocomplete="off"
                       placeholder="输入企业联系方式"
                       class="layui-input">
            </div>
        </div>
        <hr class="layui-col-lg-offset1">
        <div>
            <label class="layui-form-label">企业成立日期</label>
            <div class="layui-input-block">
                <input type="text" name="establish_date" id="establish_date" th:attr="value=${enterEstablelish}"
                       lay-verify="date" placeholder="输入企业成立日期"
                       autocomplete="off" class="layui-input">
            </div>
        </div>

        <hr class="layui-col-lg-offset1">
        <div>
            <label class="layui-form-label">企业LOGO</label>
            <div class="layui-upload">
                <div class="layui-upload-list">
                    <img class="layui-upload-img" name="logo" th:attr="src=${enterLogo}" id="demo1"
                         style="width: 150px;height: 150px; border: 1px solid #CCCCCC; padding: 5px">
                    <p id="demoText"></p>
                </div>
            </div>
        </div>
    </div>
    </div>
    <div class="layui-row layui-col-xs6">
        <div>
            <label class="layui-form-label">企业排序</label>
            <div class="layui-input-block">
                <input type="text" name="enter_order" lay-verify="enter_order" th:attr="value=${enterSort}"
                       autocomplete="off"
                       placeholder="输入企业排序"
                       class="layui-input">
            </div>
        </div>
        <hr class="layui-col-lg-offset1">
        <div>
            <label class="layui-form-label">企业状态</label>
            <div class="layui-input-block">
                <select name="enter_status" lay-verify="enter_status">
                    <option value=""></option>
                    <option value="0" th:selected="${enterStatus == 0}">不启用</option>
                    <option value="1" th:selected="${enterStatus == 1}">启用</option>
                </select>
            </div>
        </div>
        <hr class="layui-col-lg-offset1">
        <div>
            <label class="layui-form-label">企业人员上限</label>
            <div class="layui-input-block">
                <input type="number" name="person_num" lay-verify="person_num" th:attr="value=${enterPerson}"
                       autocomplete="off"
                       placeholder="输入企业人数上限"
                       class="layui-input">
            </div>
        </div>
        <hr class="layui-col-lg-offset1">
        <div class=" layui-form-text">
            <label class="layui-form-label">企业评价</label>
            <div class="layui-input-block">
                <textarea placeholder="请输入内容" name="comment_id" lay-verify="comment_id" th:text="${enterComment}"
                          class="layui-textarea"></textarea>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="demo1">提交</button>
        </div>
    </div>
</form>
<script src="layui/layui.js"></script>
<script>
    layui.use(['form', 'laydate', 'upload'], function () {
        let $ = layui.jquery, form = layui.form
            , layer = layui.layer
            , laydate = layui.laydate,
            upload = layui.upload;
        form.render();
        let filename = '';
        //上传图片
        let uploadInst = upload.render({
            elem: '#demo1'
            , url: '/upload/'
            , before: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $('#demo1').attr('src', result); //图片链接（base64）
                });
            }
            , done: function (res) {
                //如果上传失败
                if (res.code > 0) {
                    return layer.msg('上传失败');
                }
                filename = res.data.filename;
                //上传成功
            }
            , error: function () {

            }
        });
        //日期
        laydate.render({
            elem: '#establish_date'
        });

        //自定义验证规则
        form.verify({
            enter_name: function (value) {
                if (value == "") {
                    return '请输入企业名字';
                }
            }

        });

        //监听提交
        form.on('submit(demo1)', function (data) {
            let  imageHoleUrl = $('#demo1')[0].src;
            let field = data.field;
            if(filename === ''){
                field.filename = imageHoleUrl.substr(imageHoleUrl.lastIndexOf('/')+1);
            }else{
                field.filename = filename;
            }
            $.post('/sys/modifyEnter',field,function (resp) {
                if(resp.code === "0"){
                    parent.layui.table.reload('enter_table',{page: {curr: 1}}); //弹出层窗口修改父表格
                    layer.msg(resp.msg);
                }else{
                    layer.msg(resp.msg);
                }
            })
            return false;
        });

    });
</script>
</body>
</html>